# -*- coding: utf-8 -*-
# @Time    : 2020/7/14 9:54
# @Author  : ZhaoHexin
# @File    : Test.py
# @Description  : 测试用

# coding=utf-8
'''''
加密的一方和解密的一方必须提前确定好key值
'''
import binascii
from pyDes import des, PAD_PKCS5


def des_encrypt(s):
    """
    DES 加密
    :param s: 原始字符串
    :return: 加密后字符串，16进制
    """
    secret_key = 'edmundzy'
    iv = secret_key
    k = des(secret_key, pad=None, padmode=PAD_PKCS5)
    en = k.encrypt(s)
    list_en = [x for x in en]
    text = ""
    # 进行数据整理及拼接
    for i in list_en:
        # 转成16进制并进行拼接
        # 如果小于16 则前边加0
        text += "0" + hex(i).replace("0x", "") if i < 16 else hex(i).replace("0x", "")
    return text


def des_descrypt(s):
    """
    DES 解密
    :param s: 加密后的字符串，16进制
    :return: 解密后的字符串
    """
    secret_key = 'edmundzy'
    iv = secret_key
    k = des(secret_key, padmode=PAD_PKCS5)
    de = k.decrypt(binascii.a2b_hex(s))
    return str(de,"utf-8")


# str_en = des_encrypt("""<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>
# <Accounts>
# 	<AccountInfo>
# 		<Major code="ydldlpx_00GJ" name="月度劳动力调查" />
# 		<Version code="0" version="" />
# 		<AccountId id="1000514" />
# 		<AccountPwd pwd="12345678" />
# 		<AccountDisplayName name="user" />
# 		<PhoneNumber phonenum="13333333312" />
# 		<RegionCode value="66080751151500001" />
# 	</AccountInfo>
# </Accounts>""".encode("utf-8"))
# print(str_en)
text_2 = "916750951cb7133dd6b683f66ebaaf8f8451c4e758ec353cb21f9d18746ec5c13040f74038550ab27befb1a47f5b30a711a8127513d44b46584b2c5b08a299086820eb61ec507f67e1c1bb851924c45ecebcdf02cb234d555a627c2a94b35220e1c1bb851924c45e5278c163b743d39a7a8d9d3dc1d2f27130d75a3aa10c399184f12de131433fc93788d33906edc3ab1829c877176b45a91484cab93577b0e14e5efabab9054165e1c1bb851924c45e36895e37eb67261aa3e85877c013818140fc3c2ccd73010aee040667b806ca1d3005ebfcd165ade467d59cb17c6bbd2f32ced575740fe3d84b23571334e09bb564e7a5fd03f1e82ee1c1bb851924c45ed00638931574b02ca51af7e32200a1a88c8072c24bbc246f2e1791a5cb0555320394e0db457651220807abe170aa6d70bca11069dc573794dd58a1b8fa1ff45b9fc36ed210381e0871c9c778e171886bb16e9e36eca34a76d3f0b5e49a040cb776a1facc21862db60cef99a09f27f5d213c56d251aff0f3d4e5efabab9054165e1c1bb851924c45edaf01a018cc00359774c985a0450882c23f34b07632e4078dbaaf2c4341d45936ec2be9412c48c5971c9c778e171886b086fe574daff266d76740651de379840e290b2fb83f425b91110de5735ddaf11"
# if str_en == text_2:
#     print("111")
str_de = des_descrypt('916750951cb7133dd6b683f66ebaaf8f8451c4e758ec353cb21f9d18746ec5c13040f74038550ab27befb1a47f5b30a711a8127513d44b4658cd337bc6a9de7c610e4f063a5a29a25a9903691d12d14c7424043e444d8a930394e0db457651222ea2ee069db085e338cfbe48379cbfe8e1cae993d3aa89200430ed981017c15adcb339c01dbc838a5d6a77bd21bace5fe13aba412582e188c1f6fa65fedb339e45a053d7b17cf5f34e5efabab9054165e1c1bb851924c45e36895e37eb67261aa3e85877c013818140fc3c2ccd73010aee040667b806ca1d3005ebfcd165ade467d59cb17c6bbd2f32ced575740fe3d84b23571334e09bb564e7a5fd03f1e82ee1c1bb851924c45ed00638931574b02ca51af7e32200a1a88c8072c24bbc246f2e1791a5cb0555320394e0db457651220807abe170aa6d70bca11069dc573794dd58a1b8fa1ff45bd0d0c1fff22c2a9b4e5efabab9054165e1c1bb851924c45e35690257ccc2b8eb1dc3a2d6ef6241dd6d3af235da4e7df1f13fcdecec9b70ca9ed121e7a8399372e1c1bb851924c45e90fadef02f155d47e4cde88836412126e8bde345cb43eaf4631129f022a640e075cdcde3eaf50ee633ce2f5d329845970571715581f594e0aa57c732069e1ac9f28b31c438e6722d2c0b7cef127c7043')
# text_1 = """<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>
# <Accounts>
# 	<AccountInfo>
# 		<Major code="ydldlpx_00GJ" name="月度劳动力调查" />
# 		<Version code="0" version="" />
# 		<AccountId id="1000514" />
# 		<AccountPwd pwd="12345678" />
# 		<AccountDisplayName name="user" />
# 		<PhoneNumber phonenum="13333333312" />
# 		<RegionCode value="66080751151500001" />
# 	</AccountInfo>
# </Accounts>"""
print(str_de)
# if text_1 == str_de:
#     print(222)
